/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-10 11:43:59
 * @LastEditTime: 2021-12-31 14:16:29
 * @LastEditors: 张澜馨
 */

class DZDateUtil {

    formatConversion(te: string) {
        if ((te + "").nyIsEmpty()) {
            return "——"
        }
        if (parseInt(te) == 0) {
            return "——"
        }
        var time = null;
        if ((te + "").length == 10) {
            time = new Date(parseInt(te) * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        } else {
            time = new Date(te);
        }
        var y = time.getFullYear();
        var m = time.getMonth() < 9 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
        var d = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
        var h = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
        var mm = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
        var s = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
        // var timedate = y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
        var timedate = y + '年' + m + '月' + d + '日';
        return timedate;
    }

    
    formatConversion2(te: string) {
        if ((te + "").nyIsEmpty()) {
            return "——"
        }
        if (parseInt(te) == 0) {
            return "——"
        }
        var time = null;
        if ((te + "").length == 10) {
            time = new Date(parseInt(te) * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        } else {
            time = new Date(te);
        }
        var y = time.getFullYear();
        var m = time.getMonth() < 9 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
        var d = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
        var h = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
        var mm = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
        var s = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
        // var timedate = y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
        var timedate = y + '-' + m + '-' + d;
        return timedate;
    }
    
    formatConversionTotal(te: string) {
        if ((te + "").nyIsEmpty()) {
            return "——"
        }
        if (parseInt(te) == 0) {
            return "——"
        }
        var time = null;
        if ((te + "").length == 10) {
            time = new Date(parseInt(te) * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        } else {
            time = new Date(te);
        }
        var y = time.getFullYear();
        var m = time.getMonth() < 9 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
        var d = time.getDate() < 10 ? '0' + time.getDate() : time.getDate();
        var h = time.getHours() < 10 ? '0' + time.getHours() : time.getHours();
        var mm = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes();
        var s = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();
        var timedate = y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
        return timedate;
    }

    /**
     * 计算离结束日期还有几天
     * @param end 
     * @returns 
     */
    subSurplusDays(end: number) {
        var now = (new Date().getTime() / 1000);
        if (now > end) {
            return 0;
        }
        var daySecond = 24 * 60 * 60;
        var surDay = Math.ceil((end - now) / daySecond);
        if (surDay == 0) {
            return 1;
        }
        return surDay;
    }


    /**
     * 根据天数获得结束日期 
     * @param day 
     */
    getEndDate(day: number) {
        var now = Math.ceil(new Date().getTime() / 1000);
        var daySecond = day * 24 * 60 * 60;
        return now + daySecond;
    }

}
const dateUtil = new DZDateUtil();
export default dateUtil;
